package com.flw.eslab.service.impl;

import java.io.File;

import com.flw.eslab.dao.ResourceDao;
import com.flw.eslab.dto.PageInfo_Dto;
import com.flw.eslab.model.Report;
import com.flw.eslab.model.Resource;
import com.flw.eslab.service.ResourceManager;



//@Service("resourceManager")
public class ResourceManagerImpl implements ResourceManager {
	private ResourceDao resourceDao;

	@Override
	public boolean add(Resource resource) {
		if(resource.getName()==null||resource.getName().equals("")){
			return false;
		}else{
			resourceDao.save(resource);
			return true;
		}
	}

	@Override
	public boolean delect(Resource resource) {
			if(resource.getId()==null)
				resource.setId(0);
			if(resourceDao.findById(Resource.class, resource.getId())==null){
				return false;
			}else{
				resourceDao.deleteById(Resource.class, resource.getId());
				return true;
			}
	}

	@Override
	public boolean modify(Resource resource) {
		if(resource.getId()==null)
			resource.setId(0);
		if(resourceDao.findById(Resource.class, resource.getId())==null||resource.getName()==null||resource.getName().equals("")){
			return false;
		}else{
			resourceDao.update(resource);
			return true;
		}
	}

	@Override
	public File output() {
		return null;
	}

	@Override
	public PageInfo_Dto load( PageInfo_Dto pageInfo_Dto) {
		int pageNow=pageInfo_Dto.getPageNow()==null?1:pageInfo_Dto.getPageNow();
		int pageSize=pageInfo_Dto.getPagesize()==null?5:pageInfo_Dto.getPagesize();	
		return resourceDao.findByPageInfo(Resource.class, pageNow, pageSize, null, null);
	}

	@Override
	public Resource check(String id) {
		return resourceDao.findById(Resource.class, id);
		
	}
	/*-------------------------------*/
	@javax.annotation.Resource
	public void setResourceDao(ResourceDao resourceDao) {
		this.resourceDao = resourceDao;
	}

	

}
